home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / c-tools / c_examples / led / led_example.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-03  |  2.2 KB  |  95 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. // Led Class Example
  3. // 5.18.96 Deryk Robosson
  4.  
  5. //////////////////////////////////////////////////////////////////////////////
  6. // Includes
  7. #include "aframe:include/amigaapp.hpp"
  8. #include "aframe:include/window.hpp"
  9. #include "aframe:include/button.hpp"
  10. #include "aframe:include/rect.hpp"
  11. #include "aframe:include/led.hpp"
  12.  
  13. //////////////////////////////////////////////////////////////////////////////
  14. // ControlWindow Class Definition
  15.  
  16. class ControlWindow : public AFWindow
  17.  
  18. {
  19. public:
  20.     ControlWindow();
  21.     virtual void OnGadgetUp(LPIntuiMessage imess);
  22.     virtual void OnNewSize(LPIntuiMessage imess);
  23.     virtual ULONG WindowFlags();
  24.  
  25.     AFLed       led;
  26.     AFButton    up;
  27.     AFButton    down;
  28.  
  29.     short       value;
  30. };
  31.  
  32. //////////////////////////////////////////////////////////////////////////////
  33. // ControlWindow Implementation routines
  34.  
  35. ControlWindow::ControlWindow()
  36.     :value(0)
  37. {
  38. }
  39.  
  40. void ControlWindow::OnGadgetUp(LPIntuiMessage imess)
  41. {
  42.     switch(((struct Gadget*)imess->IAddress)->GadgetID) {
  43.     case 100:
  44.         if(++value>99)
  45.             value=0;
  46.         led.m_Global.DigitPairs[0]=value; //set value for digit pairs
  47.         led.Create(led.m_Global.Window, &led.m_Global.rect);
  48.         break;
  49.     case 101:
  50.         if(--value<0)
  51.             value=99;
  52.         led.m_Global.DigitPairs[0]=value; //set value for digit pairs
  53.         led.Create(led.m_Global.Window, &led.m_Global.rect);
  54.         break;
  55.     default:
  56.         AFWindow::OnGadgetUp(imess);
  57.         break;
  58.     }
  59. }
  60.  
  61. void ControlWindow::OnNewSize(LPIntuiMessage imess)
  62. {
  63.     led.RefreshImage();
  64. }
  65.  
  66. ULONG ControlWindow::WindowFlags()
  67. {
  68.     return (AFWindow::WindowFlags() | WFLG_GIMMEZEROZERO);
  69. }
  70.  
  71. //////////////////////////////////////////////////////////////////////////////
  72. // MAIN
  73.  
  74. void main()
  75. {
  76.     AFAmigaApp theApp;
  77.     ControlWindow win;
  78.     AFRect rect(10,10,410,310);
  79.  
  80.     win.Create(&theApp,&rect,"AFrame Led Example");
  81.  
  82.     rect.SetRect(0,0,100,100);
  83.     win.led.Create(&win,&rect);
  84.  
  85.     rect.SetRect(100,0,150,30);
  86.     win.up.Create("Increase",&win,&rect,100);
  87.  
  88.     rect.SetRect(152,0,202,30);
  89.     win.down.Create("Decrease",&win,&rect,101);
  90.  
  91.     win.RefreshGadgets();
  92.  
  93.     theApp.RunApp();
  94. }
  95.